import { onMounted, onUnmounted } from "vue";

/**
 * window resize hook
 * @param initExe 
 * @param handle 
 */
export default function useWindowResize(initExe = false, handle: Function = () => { }) {

    const onResize = () => {
        const dimensions = {
            width: window.innerWidth,
            height: window.innerHeight
        };

        handle && handle(dimensions);
    }

    onMounted(() => {
        window.addEventListener("resize", onResize);

        initExe && onResize();
    });

    onUnmounted(() => {
        window.removeEventListener("resize", onResize);
    });

}